//
//  KFDAccountManager.h
//  KFD
//
//  Created by JIRENTIANXIANG on 6/8/15.
//  Copyright (c) 2015 KFD. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "KFDClient.h"
#import "KFDUserAddress.h"

#define KFDLoginSuccessNotification @"KFDLoginSuccess"
#define KFDAccountInfoReadyNotificatoin @"KFDAccountInfoReady"

typedef void(^KFDGetInjectionInterfaceSuccessHandler)(NSString* injection);
typedef void(^KFDGetWithdrawInterfaceSuccessHandler)(NSString* withdraw);

@interface KFDAccountManager : NSObject

@property (atomic,readonly,getter=isLogin) BOOL login;
@property (atomic,readonly,getter=isVIP) BOOL VIP;
@property (atomic,readonly,getter=isVIPQualified) BOOL VIPQualified;
@property (atomic,copy,readonly) NSString* nickname;
@property (atomic,copy,readonly) NSString* realName;
@property (atomic,copy,readonly) NSString* gender;
@property (atomic,copy,readonly) NSString* phoneNumber;
@property (atomic,copy,readonly) NSString* emailAddress;
@property (atomic,copy,readonly) NSString* avatar;

@property (atomic,strong,readonly) NSHTTPCookie* financialServiceCookie;
@property (atomic,copy,readonly) NSString* injectionUrl;
@property (atomic,copy,readonly) NSString* withdrawUrl;

+(KFDAccountManager*)sharedManager;

-(NSURLSessionTask*)registerWithPhoneNubmer:(NSString*)phoneNumber realName:(NSString*)realName checkcode:(NSString*)checkcode successHandler:(KFDRegisterSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)getCheckcodeForRegistrationWithPhoneNumber:(NSString*)phoneNumber successHandler:(KFDGetCheckcodeSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)getCheckcodeForChangingPasswordWithPhoneNumber:(NSString*)phoneNumber successHandler:(KFDGetCheckcodeSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(void)loginLastSession;
-(NSURLSessionTask*)loginWithPhoneNumber:(NSString*)phoneNumber password:(NSString *)password successHandler:(KFDLoginSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)setNickname:(NSString *)nickname password:(NSString *)password successHandler:(KFDSetNicknameAndPasswordSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)updateNickname:(NSString*)nickname successHandler:(KFDUpdateAccountInfoSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)updatePassword:(NSString*)password token:(NSString*)token successHandler:(KFDUpdateAccountInfoSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)bindEmail:(NSString*)email successHandler:(KFDBindEmailSuccessHandler)successHandler failulreHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)applyForVIPWithSuccessHandler:(KFDApplyForVIPSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)setBankAccountInfo:(KFDBankAccountInfo*)bankInfo successHandler:(KFDSetBankSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)verifyCheckcode:(NSString*)checkcode withType:(NSString *)type phoneNumber:(NSString *)phoneNumber successHandler:(KFDVerifyCheckcodeSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;
-(NSURLSessionTask*)updateAvatar:(NSString*)url successHandler:(KFDUpdateAccountInfoSuccessHandler)successHandler failureHandler:(KFDRequestFailureHandler)failureHandler;

-(void)logout;

-(void)saveUserAddress:(KFDUserAddress*)address;
-(KFDUserAddress*)userAddress;

@end

//----------------------------------------------------------------------------------

typedef void(^KFDAccountManagerIllegalInputHandler)(NSString* message);

@interface KFDAccountManager (BusinessRules)

-(BOOL)phoneNumberLengthExceedLimit:(NSInteger)length;
-(BOOL)checkcodeLengthExceedLimit:(NSInteger)length;
-(BOOL)checkRealName:(NSString*)realName illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;
-(BOOL)checkPhoneNumber:(NSString*)phoneNumber illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;
-(BOOL)checkCheckcode:(NSString*)checkcode illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;
-(BOOL)checkNickname:(NSString*)nickname illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;
-(BOOL)checkPassword:(NSString*)password illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;
-(BOOL)checkEmail:(NSString*)email illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;
-(BOOL)checkUserAddress:(KFDUserAddress*)userAddress illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;

-(BOOL)checkBankAccountInfo:(KFDBankAccountInfo*)bankAccountInfo illegalInputHandler:(KFDAccountManagerIllegalInputHandler)handler;

@end
